import json

def get_stored_username():
    '''如果存储了用户名，就获取他。'''
    filename = 'username.json'
    try:
        with open(filename) as f:
            username = json.load(f)
    except FileNotFoundError:
        return None
    else:
        return username

def greet_user():
    '''问候用户并且指出他的名字'''
    username = get_stored_username()
    if username:
        print(f"Welcome back,{username}")
    else:
        username = input("What's your name?")
        filename = 'username.json'
        with open(filename,'w') as f:
            json.dump(username,f)
        print(f"We'll remember you when you come back,{username}")

greet_user()  #这是一次调用，并不是定义函数的结束


